package com.yanqu.road.server.logic.recharge;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.entity.recharge.RechargeOrder;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityMallModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.activity.able.ActivityAbleMgr;
import com.yanqu.road.utils.property.PropertyHelper;

/**
 * 跨域冲榜现金礼包
 */
public class ChannelRankRecharge extends BaseRecharge {

    public ChannelRankRecharge(GamePlayer player, MallInfo mallInfo, ActivityInfo activityInfo) {
        super(player, mallInfo, activityInfo);
    }

    @Override
    protected boolean isRepeatedBuy(String orderNo) {
        if(player.getModule(ActivityMallModule.class).isOverLimitBuyCount(mallInfo, 1)){
            return true;
        }
        int activityId = 0;
        if(null != activityInfo){
            activityId = activityInfo.getActivityId();
        }
        if ("1".equals(mallInfo.getCanBuyParam()) && !ActivityAbleMgr.isAble(player.getUserId(), activityId)) {
            return true;
        }
        return false;
    }

    @Override
    protected void repeatedBuyLogic() {

    }

    @Override
    protected String addMall(String orderNo, RechargeOrder rechargeOrder) {
        if(null == mallInfo){
            logger.error("ChannelRankRecharge add mall fail,mallInfo is null,orderNo:{}", orderNo);
            return "";
        }
        player.getModule(CurrencyModule.class).addCurrency(PropertyHelper.parseStringToProperty(mallInfo.getReward()),
                eLogMoneyType.Recharge, eLogMoneyType.ReChargeGet);
        return mallInfo.getReward();
    }

}
